<template>
  <el-form ref="form" :model="form" label-width="180px">
    <el-form-item label="运营模式">
      <el-radio-group v-model="form['operateMode']">
        <el-radio label="2">平台模式</el-radio>
        <el-radio label="1">个人模式</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="小程序标题">
      <el-input v-model="form['wxappTitle']"/>
    </el-form-item>
    <el-form-item label="首页轮播图">
      <el-switch v-model="form['carouselStatus']"/>
    </el-form-item>
    <el-form-item label="小程序主色">
      <el-color-picker v-model="form['wxappColor']"/>
    </el-form-item>
    <el-form-item label="小程序首页字体颜色">
      <el-color-picker v-model="form['homeFontColor']"/>
    </el-form-item>
    <el-form-item label="首页列表显示模式">
      <el-radio-group v-model="form['homeShowMode']">
        <el-radio label="2">单列</el-radio>
        <el-radio label="3">单列(大图)</el-radio>
        <el-radio label="1">双列</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="视频页列表模式">
      <el-radio-group v-model="form['videoShowMode']">
        <el-radio label="2">单列</el-radio>
        <el-radio label="3">单列(大图)</el-radio>
        <el-radio label="1">双列</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="播放列表页模式">
      <el-radio-group v-model="form['listShowMode']">
        <el-radio label="2">单列</el-radio>
        <el-radio label="3">单列(大图)</el-radio>
        <el-radio label="1">双列</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" class="bg-green" @click="submitForm('form')">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  export default {
    data() {
      return {
        form: {}
      }
    },
    created() {
      this.getSiteConfig()
    },
    methods: {
      getSiteConfig() {
        const url = '../videoAdmin/setting/getDataList'
        const data = {
          type: 'style'
        }
        this.$store.dispatch('GetConnect', { url, data }).then(res => {
          this.form = res.data;
          this.form.carouselStatus = this.form.carouselStatus === 1;
        }).catch(e => {
          this.$message.error(e.msg + ',请刷新或联系管理员')
        })
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const url = '../videoAdmin/setting/updateData'
            const data = Object.assign({}, this.form)
            data.carouselStatus = data.carouselStatus ? 1 : 0
            data.type = 'style'
            this.$store.dispatch('GetConnect', { url, data }).then(res => {
              this.$message.success(res.msg)
              this.getSiteConfig()
            }).catch(e => {
              this.$message.error(e.msg)
            })
          } else {
            this.$message.error('提交失败,请检查必填项')
          }
        })
      }
    }
  }
</script>

<style lang="scss" type="text/scss" scoped>
  @import '../../../../styles/index.scss';
  .el-form {
      max-width: 900px;
  }
</style>
